import {defineStore} from "pinia"
import {ref} from "vue";
import {logoutApi} from "@/api/loginApi.js";
import router from "@/router/router.js";
import {useUserStore} from "@/store/userStore.js";
import {ElMessage} from "element-plus";

export const useAccountStore = defineStore("accountStore",()=>{
    let showLoginDialog = ref(false);
    let showRegisterDialog = ref(false);
    let showChangePasswordDialog = ref(false);

    /**
     * 退出登录
     */
    const logout = async ()=>{
        //发起退出登录请求
        await logoutApi()
        // 清除localstorage中的数据
        useUserStore().userInfo = {}
        localStorage.setItem('token','')
        // 路由到首页
        await router.push('/home')

    }
    return{
        showLoginDialog,
        showChangePasswordDialog,
        showRegisterDialog,
        logout
    }
})